package com.livideo.emptyproject;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MainRecyclerAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final Context mContext;
    private final List<String> datas;

    public MainRecyclerAdapter(Context mContext, List<String> datas) {
        this.mContext=mContext;
        this.datas=datas;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view =View.inflate(mContext,R.layout.item_content,null);
        return new MyViewHolder(view,mContext);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((MyViewHolder)holder).setData(datas.get(position));
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    static class MyViewHolder extends RecyclerView.ViewHolder{
        private final TextView textView;
        private final ConstraintLayout item_view;
        private final Context context;

        public MyViewHolder(@NonNull View itemView,Context context) {
            super(itemView);
            this.context=context;
            textView=itemView.findViewById(R.id.textView);
            item_view=itemView.findViewById(R.id.item_view);


        }
        public void setData(String s) {
            textView.setText(s);
            item_view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context,"吐司吐司吐司",Toast.LENGTH_SHORT).show();
                }
            });
        }
    }


}
